package com.zishi.controller;


import com.zishi.model.pojo.Article;
import com.zishi.service.UserArticleRefService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 * 用户点赞和收藏的文章表 前端控制器
 * </p>
 *
 * @author TP
 * @since 2022-05-05 08:53:41
 */
@RestController
@RequestMapping("/zishi/userArticle")
public class UserArticleRefController {

    @Autowired
    private UserArticleRefService userArticleRefService;

    /**
     * 根据用户id获取用户的所有收藏
     */
    @GetMapping("/{userId}")
    public List<Article> getAllUserArticle(@PathVariable Integer userId){
        return userArticleRefService.getBatchUserArticle(userId);
    }

    /**
     * 用户点赞该文章
     */
    @PostMapping("/like")
    public boolean userLikeArticle(Integer userId, Integer articleId) {
        return userArticleRefService.userLikeArticle(userId, articleId);
    }

    /**
     * 用户收藏该文章
     */
    @PostMapping("/collect")
    public boolean userCollectArticle(Integer userId, Integer articleId) {
        return userArticleRefService.userCollectArticle(userId, articleId);
    }

    /**
     * 用户取消点赞该文章
     */
    @PostMapping("/cancelLike")
    public boolean userCancelLikeArticle(Integer userId, Integer articleId) {
        return userArticleRefService.userCancelLikeArticle(userId, articleId);
    }

    /**
     * 用户取消收藏该文章
     */
    @PostMapping("/cancelCollect")
    public boolean userCancelCollectArticle(Integer userId, Integer articleId) {
        return userArticleRefService.userCancelCollectArticle(userId, articleId);
    }



}
